package com.example.gongming.fenshux;

import java.util.Map;

/**
 * Created by Gongming on 2015/9/9.
 */
public class GFenshu {

    public int getFenzi() {
        return fenzi;
    }

    public void setFenzi(int fenzi) {
        this.fenzi = fenzi;
    }

    private int fenzi;

    public int getFenmu() {
        return fenmu;
    }

    public void setFenmu(int fenmu) {
        this.fenmu = fenmu;
    }

    private int fenmu;

    public GFenshu(int num1,int num2)
    {
        fenzi=num1;
        fenmu=num2;
    }

    public GFenshu(String str_num1,String str_num2)
    {
        fenzi=Integer.parseInt(str_num1);
        fenmu=Integer.parseInt(str_num2);
    }

    public GFenshu add(GFenshu f2){
        return new GFenshu(getFenzi()*f2.getFenmu()+getFenmu()*f2.getFenzi(),getFenmu()*f2.getFenmu());
    }

    public GFenshu sub(GFenshu f2){
        return new GFenshu(getFenzi()*f2.getFenmu()-getFenmu()*f2.getFenzi(),getFenmu()*f2.getFenmu());
    }

    public GFenshu cheng(GFenshu f2){
        return new GFenshu(getFenzi()*f2.getFenzi(),getFenmu()*f2.getFenmu());
    }

    public GFenshu chu(GFenshu f2){
        return new GFenshu(getFenzi()*f2.getFenmu(),getFenmu()*f2.getFenzi());
    }

    public void Jianhua(){
        int i,j;

        i=Math.max(fenzi, fenmu);
        j=Math.min(fenzi,fenmu);

        int k;
        k=gcd(i,j);

        if(k!=0) {
            fenzi = fenzi / k;
            fenmu = fenmu / k;
        }
    }

    private int gcd(int a,int b)
    {
        if(b==0 )
            return a;
        else
            return gcd(b,a%b);
    }
}
